#!/usr/bin/perl -w
print "Please input your installation path(Absolute Path):";
defined($installPath=<STDIN>) || die "Failed: The path you input is invalid.\n";
chomp($installPath);
if($installPath eq ""){
	die "Failed: You just input an empty path!\n";
}
$installPath =~ s/\/$//;
if( -d $installPath)
{
	print "The Merge tools will be installed in: $installPath \n";
}else{
	system("mkdir -p $installPath") && die "Can't create directory $installPath:$!\n";
}
print "Configure merge.pl ...\n";
open MERGESCRIPT, "merge.pl";
@mergescripts=<MERGESCRIPT>;
close MERGESCRIPT || die "Can't close merge.pl.\n";
pop @mergescripts;
push @mergescripts, "print `mono $installPath".'/ABSTMain $editscripts`;';
open MERGESCRIPT, ">merge.pl";
print MERGESCRIPT @mergescripts;
print MERGESCRIPT "\n";
close MERGESCRIPT;

print "Configure Makefile ...\n";
open MAKEFILE, "Makefile";
@make_f = <MAKEFILE>;
close MAKEFILE || die "Can't close Makefile.\n";
shift @make_f;
unshift @make_f, "INSTALLPATH=$installPath\n";
open MAKEFILE , ">Makefile";
print MAKEFILE @make_f;
close MAKEFILE;

print "Do the installation ...\n";
system("make -f Makefile");
print "Install the merge tools successfully!\n";
print "\033[0m\033[1;31mPlease add $installPath to your PATH!!!! \n\033[0m";
